package org.tea.inventory.admin.web.product;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tea.inventory.admin.annotation.LoginAdmin;
import org.tea.inventory.admin.web.admin.BaseController;
import org.tea.inventory.base.util.ResponseUtil;
import org.tea.inventory.domain.tea.Brand;
import org.tea.inventory.domain.tea.Product;
import org.tea.inventory.service.IBrandService;

import java.util.*;

/**
 * 品牌属性Controller
 * 
 * @author dongxb
 * @date 2025-04-07
 */
@Api(tags = "商品管理-品牌属性控制器")
@Slf4j
@RestController
@RequestMapping("/admin/brand")
@RequiredArgsConstructor
public class BrandController extends BaseController {

        @Autowired
        private IBrandService brandService;

        /** Integer adminId */
        
        @GetMapping("/list")
        @ApiOperation(value = "获取品牌属性列表")
        @ApiResponses(
                @ApiResponse(code = 0, message = "成功", response = Brand.class)
        )
        public Object list(
                           String id, String name,
                           @RequestParam(value = "page", defaultValue = "1") Integer page,
                           @RequestParam(value = "limit", defaultValue = "10") Integer limit,
                           String sort, String order){

            List<Brand> brandList = brandService.querySelective(id, name, page, limit, sort, order);
            int total = brandService.countSelective(id, name, page, limit, sort, order);
            Map<String, Object> data = new HashMap<>();
            data.put("total", total);
            data.put("items", brandList);

            return ResponseUtil.ok(data);
        }

        @PostMapping("/create")
        @ApiOperation(value = "新增品牌属性")
        public Object create(@Validated @RequestBody Brand brand){
            brandService.add(brand);
            return ResponseUtil.ok(brand);
        }

        @GetMapping("/read")
        @ApiOperation(value = "获取品牌属性详细信息")
        public Object read( Integer id){
            if(id == null){
                return ResponseUtil.badArgument();
            }

            Brand brand = brandService.findById(id);
            return ResponseUtil.ok(brand);
        }

        @PostMapping("/update")
        @ApiOperation(value = "修改品牌属性")
        public Object update(@Validated @RequestBody Brand brand){
            brandService.updateById(brand);
            return ResponseUtil.ok(brand);
        }

        @PostMapping("/delete")
        @ApiOperation(value = "删除品牌属性")
        public Object delete( @RequestBody Brand brand){
            brandService.deleteById(brand.getId());
            return ResponseUtil.ok();
        }

}
